<extend name="Public/base" />

<block name='style'>

    <script>
        var init_url = "{:U('index_list')}";
    </script>
    <style type="text/css">
        .toolspanel {
            width: 100%;
            height: auto;
            overflow: hidden;
            margin-top: 10px;
        }

        .toolspanel td {
            padding: 5px;
            line-height: 30px;
        }

        .toolspanel .input {
            width: 160px;
            height: 26px;
            min-height: 26px;
            border: solid 1px #AAA;
        }

        .toolspanel .numbertxt {
            width: 74px;
            height: 26px;
            min-height: 26px;
            border: solid 1px #AAA;
        }

        .toolspanel select {
            width: 160px;
            height: 26px;
            min-height: 26px;
            border: solid 1px #AAA;
        }

        .bgmain {
            width: 100%;
            overflow: hidden;
            background: #ffffff;
        }

        .btn_rest {
            font-size: 12px;
            color: #000000;
        }

        .goods_details_dl {
        	width:50px;
            margin: 0;
            padding: 0;
        }

        .goods_details_dl dt {
            float: left;
            margin-right: 10px;
        }

        .goods_details_dl dd {
            line-height: 22px;
        }

        .goods_details_dl .img {
            width: 50px;
            max-height: 50px;
        }

        .goods_list_table > tbody > tr > td {
            vertical-align: middle;
        }

        .goods_list_table > tbody > tr > td:first-child {
            vertical-align: top;
        }
        
        .goods_name{
       	    overflow: hidden;
		    text-overflow: ellipsis;
		    display: -webkit-box;
		    -webkit-line-clamp: 2;
		    -webkit-box-orient: vertical;
		    cursor:pointer;
		    color:#2a6496;
        }
        .attrs_img{
        	width: 15px;
		    margin-bottom: 3px;
        }
        .attrs_img_close{
        	width: 15px;
		    margin-bottom: 3px;
       	    -moz-transform: rotate(-90deg);
		    -webkit-transform: rotate(90deg); 
        }
        .otherinfotext{

        }
        .goodslist_item_top_border{
               border-top:4px solid #615D5D;
               
        }
        .goodslist_item_bottom_border{
            border-bottom:2px solid #615D5D;
            
        }

        input[type=radio], input[type=checkbox]{margin-top:-3px;}
    </style>

</block>

<block name="body">

    <include file="Public:timepicker" />
    
    <include file="Public:artdialog" />
    
    <form action="{:U('index_list')}" method="post" id="searchForm">
        <input type="hidden" name="status" id="status" value="1" />
        <input type="hidden" name="is_warn_number" id="is_warn_number" value="{$is_warn_number}">
        <div class="bgmain">
            <div class="row">
                <div class="col-md-12">
                    <div class="block-web" style="margin: 0;">
                        <div class="header">
                           <div class="actions_diy">
                                <a href="javascript:;" onclick="art.dialog.alert('如需添加商品，请联系进销存管理人员');" class="btn btn-default btn-primary"><i class="fa fa-plus"></i>添加商品</a>

                                 <a href="javascript:;" title="刷新当前页面" onclick="_reload_cpage()" class="btn btn-default btn-default reloadcpagebtn"><i class="fa fa-repeat"></i></a>

                            </div>
                            <h3 class="content-header"><if condition="$is_warn_number eq 1">商品警告列表<else/>商品列表</if></h3>
                        </div>

                        <div class="porlets-content">
                            <div class="row">
                                <div class="col-md-12">

                                    <div class="search_pannl_div">

                                        <table class="search_table">
                                            <tbody>

                                            <tr>
                                                <td class="single-col">
                                                    <label>关键词：</label><input type="text" id="keywords" name="keywords" placeholder="可根据商品名称/商品货号模糊搜索" style="width: 250px;" value=""/>
                                                </td>
                                                <td class="single-col">
                                                    <label>当前售价：</label>
                                                    <input type="number" name="goods_price_start" class="numbertxt numbercheck" style="width: 100px;" />到
                                                    <input type="number" name="goods_price_end" class="numbertxt numbercheck" style="width: 100px;" />
                                                </td>
                                                <td class="single-col">
                                                    <label>库存数量：</label>
                                                    <input type="number" name="goods_stock_start" class="numbertxt numbercheck" style="width: 100px;" />到
                                                    <input type="number" name="goods_stock_end" class="numbertxt numbercheck" style="width: 100px;" />
                                                </td>
                                            </tr>
                                            <tr>

                                                <td class="single-col">
                                                    <label>商品分类：</label>
                                                    <select id="cat_id" name="cat_id">
                                                        <option value="">--全部--</option>
                                                        <volist name="categorylist" id="c">                                                        	
                                                            <option value="{$c['cat_id']}">{$c['cat_name']}</option>
                                                            <volist name="c['childs']" id="childer">
                                                                <option value="{$childer['cat_id']}">&nbsp;&nbsp;|-{$childer['cat_name']}</option>
                                                            </volist>
                                                        </volist>
                                                    </select>
                                                </td>
                                               
                                                <td class="single-col">
                                                    <label>品牌：</label>
                                                    <select id="brand_id" name="brand_id">
                                                        <option value="">--全部--</option>
                                                        <volist name="brandlist" id="b">
                                                            <option value="{$b['brand_id']}">{$b['brand_name']}</option>
                                                        </volist>
                                                    </select>
                                                </td>

                                                <td class="single-col">
                                                    <label>推荐属性：</label>
                                                    <label class="checkbox-inline" style="padding-left: 0; width: 50px;">
                                                        <input type="checkbox" value="1" name="is_new">
                                                        <span class="custom-checkbox"></span> 新品
                                                    </label>
                                                    <label class="checkbox-inline" style="padding-left: 0; width: 50px;">
                                                        <input type="checkbox" value="1" name="is_hot">
                                                        <span class="custom-checkbox"></span>热销
                                                    </label>
                                                    <label class="checkbox-inline" style="padding-left: 0; width: 50px;">
                                                        <input type="checkbox" value="1" name="is_promote">
                                                        <span class="custom-checkbox"></span>特卖
                                                    </label>
                                                    <label class="checkbox-inline" style="padding-left: 0; width: 70px;">
                                                        <input type="checkbox" value="2" name="current_price_type">
                                                        <span class="custom-checkbox"></span>折扣商品
                                                    </label>

                                                    <script>
                                                        $('input[name=is_best]').val(["{:(empty($_REQUEST['is_best'])?0:1)}"]);
                                                        $('input[name=is_new]').val(["{:(empty($_REQUEST['is_new'])?0:1)}"]);
                                                        $('input[name=is_hot]').val(["{:(empty($_REQUEST['is_hot'])?0:1)}"]);
                                                    </script>
                                                </td>

                                            </tr>


                                            <tr>
                                                <td class="single-col" colspan="3">
                                                    <label>创建时间：</label>
                                                    <input name="start_time" readonly="readonly" class="laydate-icon" style="width: 167px;padding: 0px;height: 20px;" type="text" id="start_time">
                                                    &nbsp;-&nbsp;
                                                    	时间(结束)
                                                    <input name="end_time" readonly="readonly" class="laydate-icon" style="width: 167px;padding: 0px;height: 20px;" type="text" id="end_time">

                                                    <button type="button" class="btn btn-default date-quick-pick" onclick="handleDateQuickPickClick(this);goSearch('#searchBtn','load_tb_div');" data-days="0">今天</button>
                                                    <button type="button" class="btn btn-default date-quick-pick" onclick="handleDateQuickPickClick(this);goSearch('#searchBtn','load_tb_div');" data-days="7">最近7天</button>
                                                    <button type="button" class="btn btn-default date-quick-pick" onclick="handleDateQuickPickClick(this);goSearch('#searchBtn','load_tb_div');" data-days="29">最近30天</button>
                                                    <a class="btn btn-link" onclick="ClearDateQuickPickClick(this);goSearch('#searchBtn','load_tb_div');" href="javascript:;">清除日期</a>

                                                </td>
                                            </tr>
                                            <tr style="text-align: left;">
                                                <td class="single-col" colspan="3">
                                                    <label></label>
                                                    <input type='hidden' name='is_on_sale' id='is_on_sale' value='1'/>
                                                    <button type="button" class="btn btn-success" formtarget="searchForm" id="searchBtn" onclick="goSearch('#searchBtn','load_tb_div');"><i class="fa fa-search"></i> 搜索</button>
                                                    <button type="button" class="btn btn-default" onclick="clear_from()"> 查看所有</button>
                                                    &nbsp;&nbsp;
                                                    <button type="button" class="btn btn-primary" style="display:none;" onclick="exportExcel();">导出Excel</button>
                                                </td>
                                            </tr>

                                            </tbody>
                                        </table>

                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div><!--/col-md-12-->
            </div>

            <div class="row">
                <div class="col-md-12">
                    <div class="block-web" style="padding-top:0px;">
                        <ul class="nav nav-tabs" id="goods_is_on_sale">
                            <li class="active" dataid='1'><a href="javascript:;" data-toggle="tab" >已上架商品</a></li>
                            <li class="" dataid='0'><a href="javascript:;" data-toggle="tab" >已下架商品<span id='off_sale_number' class="badge badge-danger"></span></a></li>
                        </ul>
                        <div class="clearfix"></div>
                        <div class="porlets-content" style="margin-top:2px;">
                            <div class="table-responsive" id="load_tb_div">
                                <div style="height:100px;line-height:100px;text-align:center;">
                                    <img src="/Public/Admin/images/icon32_loading_light218877.gif" />
                                    	加载中...
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </form>
    
</block>

<block name="script">

    <!-- select2 插件 -->
    <link href="/Public/static/select2/css/select2.min.css?v={:C('CURRENT_FILE_VERSION')}" rel="stylesheet" />
    <script type="text/javascript" src="/Public/static/select2/js/select2.full.min.js?v={:C('CURRENT_FILE_VERSION')}"></script>
    <!-- 加载 select2 语言包  -->
    <script type="text/javascript" src="/Public/static/select2/js/i18n/zh-CN.js?v={:C('CURRENT_FILE_VERSION')}"></script>

    <script type="text/javascript">
        var init_url = "{:U('index_list')}";
        $(function () {
            _load_html_byurl("{:U('index_list')}", "load_tb_div");
        });
    </script>
    <script>
        var start_timepicker = $('#start_time').datetimepicker({
            numberOfMonths: 2,
            showSecond: !0,
            onClose: function (t) {
                $('#end_time').datetimepicker("option", "minDate", t);
            }
        });

        var end_timepicker = $('#end_time').datetimepicker({
            numberOfMonths: 2,
            showSecond: !0,
            onClose: function (t) {
                $('#start_time').datetimepicker("option", "maxDate", t);
            }
        });

        $(function () {

            $('#brand_id').select2({ language: "zh-CN" });
            $('#shangjia').select2({ language: "zh-CN" });
            $('#country_id').select2({ language: "zh-CN" });
            $('#suppliers_id').select2({ language: "zh-CN" });
            $('#cat_id').select2({ language: "zh-CN" });


            $(".numbercheck").keyup(function () {
                var value = $(this).val().replace(/[^0-9.]/g, '');
                $(this).val(value);
            }).blur(function () {
                check(this);
            });


            	
            $('div').delegate('.goods_name','mouseover',function(){
            	$(this).css('text-decoration','underline');
            });
            $('div').delegate('.goods_name','mouseout',function(){
            	$(this).css('text-decoration','none');
            });


            $('#goods_is_on_sale li').click(function(){
                var is_no_sale=$(this).attr('dataid');
                $("#is_on_sale").val(is_no_sale);
                $(this).addClass('active').siblings().removeClass('active');
                goSearch('#searchBtn','load_tb_div');
            });


        });
        function check(e) {
            var re = /^\d+(?=\.{0,1}\d+$|$)/
            if (e.value != "") {
                if (!re.test(e.value)) {
                    e.value = "";
                    e.focus();
                }
            }
        }

        //设置商品状态
        function _set_status_value(val) {
            $("#status").val(val);

            goSearch('#searchBtn', 'load_tb_div');
            // _reload_currentpage_datalist("load_tb_div");
        }
        function allchheckChange() {
            $("#tbodylist input[type='checkbox']").prop("checked", $("#allchheck").is(":checked"));
        }

        //是否上架
        function batch_opt(obj) {
            var url = $(obj).attr("data-url");
            var title = $(obj).attr("data-title");
            var selectedarray = new Array();
            //询问框
            $("#tbodylist input[type='checkbox']:checkbox").each(function (index, obj) {
                if ($(obj).prop("checked") == true) {
                    selectedarray.push($(obj).val());
                }
            });

            if (selectedarray.length <= 0) {
                layermsg("商品至少选择一条")
            } else {
              art.dialog.confirm(title, function () {
                var strselected = selectedarray.join(",");
                $.post(url, { "ids": strselected }, function (data) {
                    if (data.status == 1) {
                        layermsg(data.info);
                        // _load_html_byurl("{:U('Goods/index_list')}", "load_tb_div");
                        _reload_currentpage_datalist("load_tb_div");
                    } else {
                        layermsg(data.info);
                    }
                });
              }, function () {

              });
            }
        }


        function layermsg(msg) {
           art.dialog.alert('<font class="tip" style="font-size: 14px;">'+msg+'</font>');
        }



        function del_one(obj) {
          art.dialog.confirm('您确认要删除此条数据吗？', function () {
            var url = $(obj).attr("data-url");
            $.post(url, function (data) {
                if (data.status == 1) {
                    layermsg(data.info);
                    // _load_html_byurl("{:U('Goods/index_list')}", "load_tb_div");
                    _reload_currentpage_datalist("load_tb_div");
                } else {
                    layermsg(data.info);
                }
            });
          }, function () {

          });
        }

        function one_sale(obj) {

            if(!confirm("您确定操作吗？")){
                return false;
            }

            var url = $(obj).attr("data-url");
            $.post(url, function (data) {
                if (data.status == 1) {
                    layermsg(data.info);
                    // _load_html_byurl("{:U('Goods/index_list')}", "load_tb_div");
                    _reload_currentpage_datalist("load_tb_div");
                } else {
                    layermsg(data.info);
                }
            });
        }

        function clear_from() {

            $("#searchForm").find("input[type='checkbox']").prop("checked", false);
            $("#searchForm").find("").prop("checked", false);
            $('form>select').val(null).trigger("change");
            $("#searchForm").find("input").val("");
            <if condition="$is_warn_number eq 1">
                    $("#is_warn_number").val("{$is_warn_number}");
            </if>
            
            goSearch('#searchBtn','load_tb_div');
        }

        /* 导出excel */
        function exportExcel(){
            var _action = $('#searchForm').attr('action');

            $('#searchForm').attr('target','_blank');
            $('#searchForm').attr('action',"{:U('exportExcel')}&");
            $('#searchForm').submit();
            $('#searchForm').removeAttr('target');
            $('#searchForm').attr('action',_action);
        }

        function show_qrcode(goods_id){
            var _url="http://www.hnjsjp.com/mobile/goods.php?id="+goods_id;
            
            art.dialog({
                padding: 0,
                title: '手机版商品二维码',
                content: '<img src="/plugins/mwepay/sdk/qrcode_big.php?data='+_url+'" width="400" height="400" />',
                lock: true
            });
        }
        
        /* 多规格 */
        function loaddingAttrItems(obj,goods_item_id,ajax_reload){
        	
        	if( typeof(ajax_reload) == 'undefined' ){
        		//goods数据id
            	var goods_id = $(obj).attr('data-id');
            	//parent tr
            	var parent_tr = $(obj).parents('#goods_item_'+goods_id);
            	
            	//数据展开标志
            	var is_expand = 1;        	
            	if( $(obj).find('img').hasClass('attrs_img') ){
            		//展开=>收起
            		is_expand = 0;
            		$(obj).find('img').removeClass('attrs_img').addClass('attrs_img_close');
                    //移除边框样式
                    $("#goods_item_"+goods_id).removeClass('goodslist_item_top_border');
                    $("#attr_item_"+goods_id).removeClass('goodslist_item_bottom_border');

            	}else{
            		//收起=>展开
            		is_expand = 1;
            		$(obj).find('img').removeClass('attrs_img_close').addClass('attrs_img');
                    //追加边框样式
                    $("#goods_item_"+goods_id).addClass('goodslist_item_top_border');
                    $("#attr_item_"+goods_id).addClass('goodslist_item_bottom_border');

            	}
            	
            	if( $('#attr_item_'+goods_id).length == 1 ){
            		if( is_expand == 1 ){
            			$('#attr_item_'+goods_id).show();
            		}else{
            			$('#attr_item_'+goods_id).hide();
            		}        		
            		return;
            	}            	
        	}else{        		
        		goods_id = obj;        		
        	}
        	
        	//todo  加载图标
            _show_public_loading();
        	
        	$("<tr id='attr_item_"+goods_id+"' class='goodslist_item_bottom_border'><td colspan='7' style='text-align:center;'><img src='/Public/Admin/images/icon32_loading_light218877.gif' />加载中,请稍等...</td></tr>").insertAfter(parent_tr);
        	
        	$.ajax({
        		url:"{:U('loaddingAttrGoodsList')}",
        		data:{'goods_item_id':goods_item_id},
        		dataType:"html",
        		type:'POST',
        		success:function(data){
        			$('#attr_item_'+goods_id).find('td').html(data);
        			
        			//隐藏加载图标
                    _hide_public_loading();
        		},
        		error:function(){
        			
        		},
        		complete:function(){
        			
        		}
        	});
        	
        }
        
        /* 跳转到详情 */
        function goDetails(goods_id){
        	window.location.href="/goods.php?id="+goods_id;
        }


        function _load_off_salenumber(){

            $.ajax({
                url:"{:U('PublicAjax/load_off_salenumber')}",
                data:null,
                dataType:"json",
                type:'GET',
                success:function(data){
                    $("#off_sale_number").html("新同步:"+data.n);
                },
                error:function(){

                },
                complete:function(){

                }
            });

        }

    </script>

</block>


